package com.example.zhou.base;

import android.app.Application;
import android.content.Context;
import android.support.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.load.engine.cache.ExternalCacheDiskCacheFactory;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.stream.HttpUrlGlideUrlLoader;
import com.bumptech.glide.module.GlideModule;
import com.bumptech.glide.request.target.ViewTarget;
import com.example.zhou.zhihunews.R;

import java.io.InputStream;

/**
 * Created by 11065 on 2016/10/24.
 */

public class GlideConfiguration implements GlideModule {

    @Override
    public void applyOptions(Context context, @NonNull GlideBuilder builder) {
        ViewTarget.setTagId(R.id.glide_id);
        builder.setDiskCache(
                new ExternalCacheDiskCacheFactory(context, "zhou", 100 * 1024 * 1024));

    }

    @Override
    public void registerComponents(Context context, final Glide glide) {
     /*   new Thread(new Runnable() {
            @Override
            public void run() {
                glide.clearDiskCache();
            }
        });*/

        glide.register(GlideUrl.class, InputStream.class, new HttpUrlGlideUrlLoader.Factory());
    }
}
